/*
 * GraphTest.cpp
 *
 *  Created on: 12 oct. 2011
 *      Author: amothe
 */

#include <cstdlib>
#include <iostream>
#include <string.h>
#include "randomgraph.h"
#include "randomtree.h"
#include "randombiparti.h"
#include "RandomSmallCover.h"
#include "FluxGraph.h"
#include "IO.h"

#include "algo.h"

#define GLOUTON 0


void runDefault();
void runWithInput(const char*,string);

void displayVector(vector<int> v) {
	vector<int>::iterator it;
	cout << "Covers : ";
	for (it = v.begin(); it != v.end(); ++it) {
		cout << *it + 1 << "  ";
	}
	cout << endl;
}

int main(int argc, char** argv) {

	bool valid_param = false;
	int algoID;
	string input_filename;

	if (argc >= 3) {
		runWithInput(argv[1],string(argv[2]));
	} else {
		runDefault();
	}
}

void runWithInput(const char* arg, string filename) {
	Graph* g = file2Graph(filename);
	vector<int> cover;

	if (strcmp(arg,"glouton")==0) {
		cover = glouton(g);
		displayVector(cover);
	} else if (strcmp(arg,"optitree")==0) {
		cover = optitree(g);
		displayVector(cover);
	} else if (strcmp(arg,"biparti2approche")==0) {
		cover = biparti2approche(g);
		displayVector(cover);
	} else if (strcmp(arg,"optibiparti")==0) {
		cover = biparti2approche(g);
		FluxGraph* fluxgraph = new FluxGraph(g,cover);
		cover = optibiparti(fluxgraph);
		displayVector(cover);
	} else if (strcmp(arg,"ApprocheVoisinage")==0) {
		cover = ApprocheVoisinage(g);
		displayVector(cover);
	} else if (strcmp(arg,"ApprocheArbre")==0) {
		cover = ApprocheArbre(g);
		displayVector(cover);
	} else {
		runDefault();
	}
}

void runDefault() {
	Graph *randomGraph = new RandomGraph(10,0.25);
	Graph *randomTree = new RandomTree(20);
	Graph *randomBiparti = new RandomBiparti(10,0.5);
	Graph *smallCover = new RandomSmallCover(10,4,0.25);
	FluxGraph *fluxGraph;

	cout << "-----------graph-------------" << endl;
	cout << randomGraph->toString() << endl;
	cout << "-----------tree--------------" << endl;
	cout << randomTree->toString() << endl;
	cout << "-----------Biparti--------------" << endl;
	cout << randomBiparti->toString() << endl;
	cout << "-----------SmallCover--------------" << endl;
	cout << smallCover->toString() << endl;


	cout << "-----------Glouton --------------" << endl;
	vector<int> covers = glouton(smallCover);
	displayVector(covers);



	cout << "-----------OptiTree --------------" << endl;
	covers = optitree(randomTree);
	displayVector(covers);

	cout << "-----------Biparti 2 approche --------------" << endl;
	covers = biparti2approche(randomBiparti);
	displayVector(covers);

	cout << "---------random biparti -------------" << endl;
	cout << randomBiparti->toString() << endl;


	cout << "----------------Flux Graph -------------" << endl;

	vector<int> coversTest;
	coversTest.push_back(0);coversTest.push_back(4);coversTest.push_back(5);
	fluxGraph = new FluxGraph(randomBiparti, covers);
	cout << fluxGraph->toString() << endl;
	cout << "S = "<< fluxGraph->S;
	cout << " T = "<< fluxGraph->T << endl;

	cout << "----------------Opti Biparti-------------" << endl;
	covers = optibiparti(fluxGraph);
	displayVector(covers);

	cout << "---------------Approche voisinage---------------" << endl;
	covers = ApprocheVoisinage(randomGraph);
	displayVector(covers);


	cout << "---------------Approche Arbre---------------" << endl;
	Graph *randomGraph2 = new RandomGraph(10,0.25);
	cout << randomGraph2->toString() << endl;
	covers = ApprocheArbre(randomGraph2);
	displayVector(covers);



	delete(randomGraph);
	delete(randomTree);
	delete(randomBiparti);
	delete(smallCover);
	delete(fluxGraph);





}
